# coding=utf-8
__author__ = 'good'
from flask_wtf import Form
from wtforms import TextField, SelectField, TextAreaField
from wtforms.validators import DataRequired, Length
from golsee.models import Category


class Admin_second_barForm(Form):
    """第二菜单编辑"""
    name = TextField('name', [DataRequired(u'请输入名称！')])
    value = TextField('value', [DataRequired(u'请输入链接！')])
    is_use = SelectField('is_use', choices=[(0, u'停用'), (1, u'在用')], coerce=int)
    seq = TextField('seq')
    icon = TextField('seq', [DataRequired(u'请输入图片类！')])


class AdminUserEditForm(Form):
    """管理员编辑用户信息"""
    nicename = TextField('nicename')
    info = TextAreaField('info', validators=[Length(min=0, max=140)])
    url = TextField('url', validators=[Length(min=0, max=100)])
    role = SelectField('role', choices=[(0, u'普通用户'), (1, u'管理员')], coerce=int)
    is_locked = SelectField('is_locked', choices=[(0, u'不锁定'), (1, u'锁定')], coerce=int)


class CategoryeditForm(Form):
    name = TextField('category name', [DataRequired(u'请输入类别名！')])
    is_use = SelectField('is_use', choices=[(0, u'停用'), (1, u'在用')], coerce=int)
    seq = TextField('seq')


class CategoryForm(Form):
    name = TextField('category name', [DataRequired(u'请输入类别名！')])
    is_use = SelectField('is_use', choices=[(0, u'停用'), (1, u'在用')], coerce=int)
    seq = TextField('seq')

    def __init__(self, *args, **kwargs):
        Form.__init__(self, *args, **kwargs)

    def validate(self):
        if not Form.validate(self):
            return False
        category = Category.query.filter_by(name=self.name.data).first()
        if category is not None:
            self.name.errors.append(u'类别名不能重复！')
            return False
        return True


class SettingsForm(Form):
    """设置"""
    blog_name = TextField(u'本站名称', [DataRequired(u'请输入博客名称！')])
    MAIL_SERVER = TextField(u'服务器地址', [DataRequired(u'请输入服务器地址！')])
    MAIL_PORT = TextField(u'服务器端口', [DataRequired(u'请输入服务器端口！')])
    MAIL_USE_TLS = SelectField(u'开 启 TLS ', choices=[('False', 'False'), ('True', 'True')], coerce=str)
    MAIL_USE_SSL = SelectField(u'开 启 SSL ', choices=[('False', 'False'), ('True', 'True')], coerce=str)
    MAIL_USERNAME = TextField(u'邮件用户名', [DataRequired(u'请输入邮件用户名！')])
    MAIL_PASSWORD = TextField(u'邮 件 密 码', [DataRequired(u'请输入邮件密码！')])
    DEFAULT_THEME = TextField(u'默认主题', [DataRequired(u'默认主题！')])
